<?php
namespace app\index\controller;
use think\Controller;
use think\Request;
use think\Db;
use think\Session;

class Personal extends Base
{
	 public  function _initialize(){
	 	$this->get_session();
		$this->heade();
	 }
   public function Centre(){
   	$date = session::get('date');
	$id = $date['id'];
   	$arr =Db::table('think_user')->where('id','EQ',$id)->field('sex,age,address,qq,weixin')->find();
	$this->assign('arr',$arr);
    return  $this->fetch();
   	
  }

  public function personal_ins(){
  	$date = session::get('date');
	$id = $date['id'];
	$arr = Request::instance()->post();
	$arr['age'] = strtotime($arr['age']);
	if($arr['weixin']){
	//微信号验证
	$isweixin =preg_match('/^[a-zA-Z]{1}[-_a-zA-Z0-9]{5,19}$/',$arr['weixin'], $matches);
	if(!$isweixin){
		$data['code'] =0;
		$data['msg'] ='请输入正确的微信号';
		return $data;
	}
	}
    if($arr['qq']){
    	//qq正则表达式 
    	$isqq= preg_match('/^[1-9][0-9]{4,14}$/', $arr['qq'], $matches);
		if(!$isqq){
			$data['code'] =0;
			$data['msg'] ='请输入正确的QQ号';
			return $data;
		}
    }
	$res = Db::table('think_user')->where('id','EQ',$id)->update($arr);
	if($res){
		$data['code'] =1;
		$data['msg'] ='提交成功';
	}else{
		$data['code'] =0;
		$data['msg'] ='系统忙，稍后再试';
	}
	return $data;
  }


  public function security(){
  	
  	return  $this->fetch();
  }
    
}

